package com.jk.myimkit.imkit.plugin.location;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.CameraPosition.Builder;
import com.jk.myimkit.R;
import com.jk.myimkit.imkit.RongBaseActivity;

import io.rong.message.LocationMessage;

public class AMapPreviewActivity extends RongBaseActivity {
    private MapView mAMapView;

    public AMapPreviewActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.rc_location_preview_activity);
        this.mAMapView = (MapView)this.findViewById(R.id.rc_ext_amap);
        this.mAMapView.onCreate(savedInstanceState);
        TextView title = (TextView)this.findViewById(R.id.rc_action_bar_title);
        title.setText(R.string.rc_plugin_location);
        this.initMap();
    }

    private void initMap() {
        AMap amap = this.mAMapView.getMap();
        amap.setMyLocationEnabled(true);
        amap.getUiSettings().setZoomControlsEnabled(false);
        amap.getUiSettings().setMyLocationButtonEnabled(false);
        Intent intent = this.getIntent();
        LocationMessage locationMessage = (LocationMessage)intent.getParcelableExtra("location");
        double lat = locationMessage.getLat();
        double lng = locationMessage.getLng();
        String poi = locationMessage.getPoi();
        amap.addMarker((new MarkerOptions()).anchor(0.5F, 0.5F).position(new LatLng(lat, lng)).title(poi).snippet(lat + "," + lng).draggable(false));
        amap.moveCamera(CameraUpdateFactory.newCameraPosition((new Builder()).target(new LatLng(lat, lng)).zoom(16.0F).bearing(0.0F).tilt(30.0F).build()));
    }

    protected void onDestroy() {
        this.mAMapView.onDestroy();
        super.onDestroy();
    }
}
